package com.yh.correct.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import com.yh.correct.model.Page;
import com.yh.correct.model.ResultData;
import com.yh.correct.service.IMentalityService;

/**
 * 心理矫正登记控制层
 * 
 * @author 王鹏程 
 * @Date 2017.03.23
 * @Time 11:09
 */
@RestController
@RequestMapping("/mentality")
public class MentalityController {

	/**
	 * 日志记录
	 */
	private static Logger logger = LogManager.getLogger(MentalityController.class);
	/**
	 * 注入心理矫正登记服务层接口
	 */
	@Autowired
	private IMentalityService mentalityService;
	/**
	 * 心理矫正登记首页跳转
	 * 
	 * @return
	 */
	@RequestMapping(value="/skip")
	public ModelAndView skip(){ 
		return new ModelAndView("education/mentality");
	}
	/**
	 * 模糊查询心理矫正登记
	 * 
	 * @param name
	 * @param jname
	 * @param pageSize
	 * @param pageNum
	 * @return
	 */
	@RequestMapping(value="/getLike")
	public ResultData getLikeMentality(String name,String jname,@RequestParam int pageSize,@RequestParam int pageNum){
		Map<String,Object> condition=new HashMap<String,Object>();
		condition.put("pageSize", pageSize);
		condition.put("pageNum", pageNum);
		condition.put("name", name);
		condition.put("jname", jname);
		Page page = mentalityService.getLikeMentality(condition);
		ResultData rd=new ResultData();
		if(page!=null){
			List<Object> mentality = new ArrayList<Object>();
			mentality.add(page);
			rd.setCode(0);
			rd.setMessage("查询成功！");
			rd.setData(mentality);
		}else{
			rd.setCode(-1);
			rd.setMessage("查询失败！");
		}
		logger.debug("心理矫正登记登记!");
		return rd;
	}
}
